﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Cost.Models;
using NBlock.MVCExtensions;
using Cost.Services;
using System.Linq.Expressions;

namespace Cost.Controllers
{
    public class OrderViewController : Controller
    {
        #region 构造函数
        private readonly ICostRepository<ReportedOrder> reportedOrderRepository;
        private readonly CommonService commonService;

        public OrderViewController(ICostRepository<ReportedOrder> reportedOrderRepository,
            CommonService commonService)
        {
            this.reportedOrderRepository = reportedOrderRepository;
            this.commonService = commonService;
        }
        #endregion

        public ActionResult Index()
        {
            ViewBag.NextMonday = CommonLogic.GetNextMonday();
            return View();
        }

        [HttpPost]
        public JsonResult List(DateTime? date, nbPageInfo pager, nbSearchCondition where)
        {
            Expression<Func<ReportedOrder, bool>> filter = null;
            if (date.HasValue)
                filter = o => o.BeginDate == date;
            var pageData = reportedOrderRepository.GetPageable(pager, filter, where);
            var data = pager.ToGridData(pageData);
            return Json(data);
        }
    }
}
